/*    */ package com.chw.interceptor;
/*    */ 
/*    */ import com.chw.admin.permission.SysPermissionMapper;
/*    */ import com.chw.annotation.PermissionSecurity;
/*    */ import com.chw.utils.CommonFieldsUtil;
/*    */ import com.chw.utils.UUIDUtil;
/*    */ import java.lang.reflect.Method;
/*    */ import java.util.HashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.web.method.HandlerMethod;
/*    */ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/*    */ 
/*    */ public class PermissionSecurityInterceptor extends HandlerInterceptorAdapter
/*    */ {
/*    */ 
/*    */   @Autowired
/*    */   private SysPermissionMapper sysPermissionMapper;
/*    */ 
/*    */   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
/*    */     throws Exception
/*    */   {
/* 31 */     String userId = CommonFieldsUtil.getCurrentUserId();
/* 32 */     if ((StringUtils.isNotBlank(userId)) && ("1".equals(userId)))
/*    */     {
/* 34 */       return super.preHandle(request, response, handler);
/*    */     }
/*    */ 
/* 37 */     if ((handler instanceof HandlerMethod))
/*    */     {
/* 39 */       HandlerMethod handlerMethod = (HandlerMethod)handler;
/*    */ 
/* 41 */       Method method = handlerMethod.getMethod();
/*    */ 
/* 43 */       PermissionSecurity permission = (PermissionSecurity)method.getAnnotation(PermissionSecurity.class);
/*    */ 
/* 45 */       if (permission == null)
/*    */       {
/* 47 */         response.setStatus(403);
/* 48 */         return false;
/*    */       }
/*    */ 
/* 51 */       String permissionId = UUIDUtil.getUUID(permission.module() + permission.name());
/* 52 */       Map map = new HashMap();
/* 53 */       map.put("userId", userId);
/* 54 */       map.put("permissionId", permissionId);
/* 55 */       List list = this.sysPermissionMapper.findByUser(map);
/* 56 */       if ((list == null) || (list.isEmpty()))
/*    */       {
/* 59 */         response.setStatus(403);
/* 60 */         return false;
/*    */       }
/*    */     }
/*    */ 
/* 64 */     return super.preHandle(request, response, handler);
/*    */   }
/*    */ }

/* Location:           E:\chenya\2017 4-21\com.chw\interceptor\
 * Qualified Name:     com.chw.interceptor.PermissionSecurityInterceptor
 * JD-Core Version:    0.6.0
 */